<?php
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();
$uniacid = $_W['uniacid'];
$store_id = $_GPC['store_id'];
if(empty($store_id)){
    message('商家id为空!','','error');
}
$info = pdo_get('cjdc_store_reconciliation',array('store_id'=>$store_id));
if(checksubmit('submit')){
    $store_id = $_GPC['store_id'];
    $store_name = $_GPC['store_name'];
    $price = (float)$_GPC['price'];
    $pz_img = $_W['attachurl'].$_GPC['pz_img'];
    if(empty($price)|| $price < 0){
        message('请输入正确结算金额!','','error');
    }
    if($price > $info['store_price']){
        message('结算金额超过可结算金额!','','error');
    }

    $data = array(
        'uniacid'=>$uniacid,
        'store_id'=>$store_id,
        'store_name'=>$store_name,
        'price'=>$price,
        'create_time'=>time(),
        'pz_img'=>$pz_img
    );
    $res = pdo_insert('cjdc_store_remit',$data);
    if($res){
        //更新对账表数据
        $data_b = array(
            'store_getprice'=>$info['store_getprice'] + $price,
            'store_price'=>$info['store_price'] - $price,
            'update_time'=>time()
        );
        pdo_update('cjdc_store_reconciliation',$data_b,array('store_id'=>$store_id));
        add_log($_W['username'],'添加商家打款记录');
        message('添加成功！', $this->createWebUrl('reconciliation'), 'success');
    }else{
        message('添加失败！','','error');
    }
}
include $this->template('web/addremit');